using DG.Tweening;
using DG.Tweening.Core;
using UnityEngine;

namespace WorkFlow.TweenGo
{
    [AddComponentMenu("TweenGO/CanvasTween")]
    public class CanvasTween : TweenGoBase<CanvasGroup, float>
    {
        [SerializeField] bool blockOnRun = false;

        protected override void Awake()
        {
            OnStartEvent.AddListener(() =>
            {
                if (blockOnRun)
                {
                    Target.blocksRaycasts = false;
                }
            });
            OnCompleteEvent.AddListener(() =>
            {
                if (blockOnRun)
                {
                    Target.blocksRaycasts = true;
                }
            });
            base.Awake();
        }

        protected override Tweener CreateTween(DOGetter<float> startValueGetter, DOSetter<float> setter, float endValue, float duration)
        {
            return DOTween.To(startValueGetter, setter, endValue, duration);
        }

        protected override void SetValue(float value)
        {
            Target.alpha = value;
        }
    }
}
